/**
 * 
 */
package com.mango.mstock;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;

import com.mango.mstock.support.MStockGlobalVars;
import com.mango.mstock.support.utils.MStockUtil;

/**
 * @author mango
 *
 */
@Deprecated
@SuppressLint("InflateParams")
public class AddFavoritePopWindow extends PopupWindow {
	
	private View conentView;
	
	public AddFavoritePopWindow() {
		Context context = MStockGlobalVars.getCurrentContext();
		LayoutInflater inflater = (LayoutInflater) context  
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		conentView = inflater.inflate(R.layout.add_favorite_pop, null);
		
        this.setContentView(conentView);  
        this.setWidth(LayoutParams.WRAP_CONTENT);  
        this.setHeight(LayoutParams.WRAP_CONTENT);  
        this.setFocusable(true);  
        this.setOutsideTouchable(false);  
        this.update();  
        
        // 半透明
        ColorDrawable dw = new ColorDrawable(0000000000);  
        // 点back键和其他地方使其消失,设置了这个才能触发OnDismisslistener ，设置其他控件变化等操作  
        this.setBackgroundDrawable(dw);  
        // mPopupWindow.setAnimationStyle(android.R.style.Animation_Dialog);  
        // 设置SelectPicPopupWindow弹出窗体动画效果  
        this.setAnimationStyle(R.style.AnimationPreview);  
        
        Button addStockBtn = (Button) conentView.findViewById(R.id.addStockBtn);
        addStockBtn.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View arg0) {
				TextView text = (TextView) conentView.findViewById(R.id.addedStockTxt);
				String code = text.getText().toString();
				if (code == null || code.isEmpty()) {
					Toast.makeText(MStockGlobalVars.getCurrentContext(), 
		    				"You must input a stock code.", Toast.LENGTH_SHORT).show();
					return;
				}
				MStockUtil.saveMyFavorite(code);
				AddFavoritePopWindow.this.dismiss();
			}
		});
        
	}
	
	public void showPopupWindow(View parent) {  
        if (!this.isShowing()) {  
            // 以下拉方式显示popupwindow  
            this.showAsDropDown(parent, parent.getLayoutParams().width / 2, 18);  
        } else {  
            this.dismiss();  
        }  
    } 

}
